{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-17T11:19:11.668236Z",
     "start_time": "2018-10-17T11:19:11.316406Z"
    },
    "collapsed": true,
    "hide_input": false
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "from torch.autograd import Variable\n",
    "from torch.optim.lr_scheduler import StepLR\n",
    "from torch.utils.data import DataLoader,TensorDataset\n",
    "import torch.utils.data as data\n",
    "import numpy as np\n",
    "import scipy.io as sio\n",
    "import math\n",
    "import argparse\n",
    "import random\n",
    "import os\n",
    "from My_Loss import HardTripletLoss\n",
    "from My_Loss import HardTripletLoss2\n",
    "from My_Loss import HardTripletLoss_D\n",
    "from tensorboardX import SummaryWriter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-17T11:19:11.671635Z",
     "start_time": "2018-10-17T11:19:11.669195Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "BATCH_SIZE = 64\n",
    "EPISODE = 200000\n",
    "TEST_EPISODE = 1000\n",
    "LEARNING_RATE =2e-5\n",
    "Weight_Deacy = 1e-6\n",
    "GPU = 0\n",
    "Margin = 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-17T11:19:12.679145Z",
     "start_time": "2018-10-17T11:19:11.673434Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "init dataset\n",
      "----------------------------------------------------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "print(\"init dataset\")\n",
    "##################################参数##################################################################\n",
    "dataroot = '../data'\n",
    "dataset = 'APY_data'\n",
    "image_embedding = 'res101'               #ResNet101层\n",
    "class_embedding = 'att'         #属性表达 85-d\n",
    "#######################################读取视觉特征###################################################################\n",
    "\n",
    "matcontent = sio.loadmat(dataroot + \"/\" + dataset + \"/\" + image_embedding + \".mat\")  #scipy loadmat\n",
    " \n",
    "feature = matcontent['features'].T         #转置 30478x2048 每一行是一个完整的样本\n",
    "\n",
    "label = matcontent['labels'].astype(int).squeeze() - 1   #matlab begin 1 ,numpy begin 0\n",
    "########################################读取属性特征###########################################################\n",
    "\n",
    "matcontent = sio.loadmat(dataroot + \"/\" + dataset + \"/\" + class_embedding + \"_splits.mat\")\n",
    "\n",
    "    \n",
    "# numpy array index starts from 0, matlab starts from 1\n",
    "trainval_loc = matcontent['trainval_loc'].squeeze() - 1    #squeeze()去掉维度中的1 AxBx1 --->AxB\n",
    "\n",
    "test_seen_loc = matcontent['test_seen_loc'].squeeze() - 1\n",
    "test_unseen_loc = matcontent['test_unseen_loc'].squeeze() - 1\n",
    "\n",
    "attribute = matcontent['att'].T    #转置 50x85 每行是整个属性向量\n",
    "\n",
    "x = feature[trainval_loc]                      # train_features trainval里面是图片的编号 begin with 0 ，19832个\n",
    "train_label = label[trainval_loc].astype(int)  # train_label  int类型没变 每个图片的lable 19832个\n",
    "train_id = np.unique(train_label)\n",
    "\n",
    "att = attribute[train_label]                   # train attributes 每个图片的属性 19832个\n",
    "\n",
    "########################add negative pairs#######################\n",
    "#x_negative = np.empty_like(x)\n",
    "#x_negative_label = np.empty_like(train_label)\n",
    "#print(x.shape[0])\n",
    "\n",
    "#for i in range(x.shape[0]):\n",
    "#    pick=np.random.choice(np.where(train_label[i]!=train_id)[0], replace=True)\n",
    "#    x_negative[i] = x[pick]\n",
    "#    x_negative_label[i] = train_label[pick]\n",
    "    \n",
    "x_test = feature[test_unseen_loc]                   # test_feature 5685个\n",
    "test_label = label[test_unseen_loc].astype(int)     # test_label   5685个\n",
    "\n",
    "x_test_seen = feature[test_seen_loc]                #test_seen_feature 4958个\n",
    "test_label_seen = label[test_seen_loc].astype(int)  # test_seen_label  4958个\n",
    "    \n",
    "test_id = np.unique(test_label)                     # test_id  10个类 ，unique去重\n",
    "att_pro = attribute[test_id]                        # test_attribute 每一类的属性向量 10x85\n",
    "\n",
    "# train set\n",
    "train_features = torch.from_numpy(x)   #np-->tensor\n",
    "#train_fearures_negative = torch.from_numpy(x_negative)\n",
    "\n",
    "sample_attributes=[]\n",
    "train_label = torch.from_numpy(train_label).unsqueeze(1) #每张图片的属性转化 ，unsqueeze(1)就是插入到第一维度 AxB维-->Ax1xB\n",
    "#train_negative_label = torch.from_numpy(x_negative_label).unsqueeze(1)\n",
    "# attributes\n",
    "all_attributes = np.array(attribute)  #所有50类属性转变为numpy数组???属性向量仍然用的numpy类型 没有转化为pytorch\n",
    "#print(all_attributes)\n",
    "    \n",
    "#print('-'*50)\n",
    "attributes = torch.from_numpy(attribute) \n",
    "#print(attribute)\n",
    "# test set\n",
    "\n",
    "test_features = torch.from_numpy(x_test)\n",
    "#print(test_features.shape)\n",
    "\n",
    "test_label = torch.from_numpy(test_label).unsqueeze(1)\n",
    "#print(test_label.shape)\n",
    "\n",
    "testclasses_id = np.array(test_id)\n",
    "#print(testclasses_id.shape)\n",
    "\n",
    "test_attributes = torch.from_numpy(att_pro).float()\n",
    "#print(test_attributes.shape)\n",
    "\n",
    "test_seen_features = torch.from_numpy(x_test_seen)\n",
    "#print(test_seen_features.shape)\n",
    "\n",
    "test_seen_label = torch.from_numpy(test_label_seen)\n",
    "\n",
    "train_data = TensorDataset( train_label, train_features )\n",
    "#train_data = TensorDataset(train_label, train_features, train_fearures_negative)\n",
    "\n",
    "#################here need new code to make triplet data#####################\n",
    "print('-'*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-17T11:19:12.682101Z",
     "start_time": "2018-10-17T11:19:12.680027Z"
    },
    "collapsed": true,
    "hide_input": false
   },
   "outputs": [],
   "source": [
    "from my_net_3 import AttributeNetwork\n",
    "from my_net_3 import MetricNetwork"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-17T11:19:14.649144Z",
     "start_time": "2018-10-17T11:19:12.683243Z"
    },
    "hide_input": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "init networks\n",
      "----------------------------------------------------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "# init network\n",
    "print(\"init networks\")\n",
    "attribute_network = AttributeNetwork(64,1600,2048)  #85d属性 1024隐藏层 2048输出 85d到2048d\n",
    "metric_network = MetricNetwork(2048,1600,2048)\n",
    "#triplet_network = TripletNetwork(attribute_network, metric_network)  #metric learning   \n",
    "attribute_network.cuda(GPU) \n",
    "metric_network.cuda(GPU)\n",
    "#attribute_network_optim = torch.optim.Adam(attribute_network.parameters(), lr=LEARNING_RATE, weight_decay=1e-5)\n",
    "#优化器adam 学习率 正则1e-5\n",
    "\n",
    "#attribute_network_scheduler = StepLR(attribute_network_optim, step_size=200000, gamma=0.5)\n",
    "#学习率每200k步 乘0.5\n",
    "attribute_network_optim = torch.optim.Adam(attribute_network.parameters(), lr=LEARNING_RATE,weight_decay=Weight_Deacy)\n",
    "metric_network_optim = torch.optim.Adam(metric_network.parameters(), lr=LEARNING_RATE,weight_decay=Weight_Deacy)\n",
    "#\n",
    "#triplet_network_optim = torch.optim.SGD(triplet_network.parameters(), lr=LEARNING_RATE,momentum=0.9 , \n",
    "#                                         weight_decay=Weight_Deacy)\n",
    "\n",
    "attribute_network_scheduler = StepLR(attribute_network_optim , step_size=40000 , gamma=0.5)\n",
    "metric_network_scheduler = StepLR(metric_network_optim , step_size=40000 , gamma=0.5)\n",
    "#\n",
    "print('-'*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-17T11:19:14.655224Z",
     "start_time": "2018-10-17T11:19:14.650122Z"
    },
    "collapsed": true,
    "hide_input": true
   },
   "outputs": [],
   "source": [
    "def compute_accuracy(test_features, test_label, test_id, test_attributes):\n",
    "    \n",
    "    test_data = TensorDataset(test_features, test_label)\n",
    "    test_batch = 32\n",
    "    test_loader = DataLoader(test_data, batch_size=test_batch, shuffle=False)\n",
    "    total_rewards = 0\n",
    "\n",
    "    sample_labels = test_id\n",
    "    sample_attributes = test_attributes\n",
    "    class_num = sample_attributes.shape[0]\n",
    "    test_size = test_features.shape[0]\n",
    "\n",
    "    print(\"class num:\", class_num)\n",
    "\n",
    "    for batch_features,batch_labels in test_loader:\n",
    "\n",
    "        batch_size = batch_labels.shape[0]\n",
    "        batch_features_ext = torch.from_numpy(batch_features.numpy().repeat(class_num, 0))\n",
    "        batch_features_ext = metric_network(Variable(batch_features_ext).cuda(GPU).float())  # 32*1024\n",
    "\n",
    "        #print(batch_features_ext)\n",
    "\n",
    "        sample_features = metric_network(attribute_network(Variable(sample_attributes).cuda(GPU).float()))\n",
    "        sample_features_ext = sample_features.repeat(batch_size, 1)\n",
    "        #print(sample_features_ext.shape)\n",
    "\n",
    "\n",
    "        relations = F.pairwise_distance(batch_features_ext, sample_features_ext, 2).view(-1, class_num)\n",
    "        re_batch_labels = []\n",
    "        for label in batch_labels.numpy():\n",
    "            index = np.argwhere(sample_labels == label)\n",
    "            re_batch_labels.append(index[0][0])\n",
    "        re_batch_labels = torch.cuda.LongTensor(re_batch_labels)\n",
    "\n",
    "\n",
    "        _, predict_labels = torch.min(relations.data, 1)\n",
    "        #print(predict_labels)\n",
    "        rewards = [1 if predict_labels[j] == re_batch_labels[j] else 0 for j in range(batch_size)]\n",
    "        total_rewards += np.sum(rewards)\n",
    "    test_accuracy = total_rewards/1.0/test_size\n",
    "    return  test_accuracy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-17T11:19:14.661995Z",
     "start_time": "2018-10-17T11:19:14.656387Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def compute_accuracy_per_class(test_features, test_label, test_id, test_attributes,cos_sim = False):\n",
    "    \n",
    "    test_data = TensorDataset(test_features, test_label)\n",
    "    test_batch = 32\n",
    "    test_loader = DataLoader(test_data, batch_size=test_batch, shuffle=False)\n",
    "    total_rewards = 0\n",
    "    #print(test_features.size())\n",
    "    sample_labels = test_id\n",
    "    sample_attributes = test_attributes\n",
    "    class_num = sample_attributes.shape[0]\n",
    "    test_size = test_features.shape[0]\n",
    "    per_class_num = np.zeros(class_num)\n",
    "    per_class_true= np.zeros(class_num)\n",
    "\n",
    "    print(\"class num:\", class_num)\n",
    "\n",
    "    for batch_features,batch_labels in test_loader:\n",
    "\n",
    "        batch_size = batch_labels.shape[0]\n",
    "        batch_features_ext = torch.from_numpy(batch_features.numpy().repeat(class_num, 0))\n",
    "        batch_features_ext = metric_network(Variable(batch_features_ext).cuda(GPU).float())  # 32*1024\n",
    "\n",
    "\n",
    "        sample_features = metric_network(attribute_network(Variable(sample_attributes).cuda(GPU).float()))\n",
    "        sample_features_ext = sample_features.repeat(batch_size, 1)\n",
    "\n",
    "        if cos_sim:\n",
    "            relations = F.cosine_similarity(batch_features_ext, sample_features_ext).view(-1, class_num)\n",
    "        else:\n",
    "            relations = F.pairwise_distance(batch_features_ext, sample_features_ext, 2).view(-1, class_num)\n",
    "        re_batch_labels = []\n",
    "        for label in batch_labels.numpy():\n",
    "            index = np.argwhere(sample_labels == label)\n",
    "            re_batch_labels.append(index[0][0])\n",
    "        re_batch_labels_id, batch_per_num = np.unique(re_batch_labels , return_counts=True) \n",
    "        re_batch_labels = torch.cuda.LongTensor(re_batch_labels)\n",
    "        \n",
    "        for each in range(re_batch_labels_id.size):\n",
    "            #print(re_batch_labels_id[each])\n",
    "            #print(batch_per_num[each])\n",
    "            per_class_num[re_batch_labels_id[each]] = per_class_num[re_batch_labels_id[each]] + batch_per_num[each]\n",
    "        #print(re_batch_labels_id)\n",
    "        #print('-'*100)\n",
    "        #print(batch_per_num)\n",
    "        #print('-'*100)\n",
    "\n",
    "\n",
    "        _, predict_labels = torch.min(relations.data, 1)\n",
    "        for j in range(batch_size):\n",
    "            if predict_labels[j] == re_batch_labels[j]:\n",
    "                per_class_true[re_batch_labels[j]] = per_class_true[re_batch_labels[j]] + 1\n",
    "            \n",
    "        \n",
    "        \n",
    "    per_accuracy = per_class_true[np.nonzero(per_class_num)] / per_class_num[np.nonzero(per_class_num)]\n",
    "    \n",
    "\n",
    "    test_accuracy = np.sum(per_accuracy)/1.0/np.count_nonzero(per_class_num)\n",
    "    \n",
    "    #print(np.count_nonzero(per_class_num))\n",
    "    return  test_accuracy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-17T11:40:56.905676Z",
     "start_time": "2018-10-17T11:19:14.663231Z"
    },
    "code_folding": [],
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "training...\n",
      "episode: 1 loss tensor(3.1876, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.09532412710706047\n",
      "gzsl: unseen=0.0476 , seen=0.0402 , h=0.0436\n",
      "____________________________________________________________________________________________________\n",
      "episode: 200 loss tensor(3.0668, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.2722420955299223\n",
      "gzsl: unseen=0.0763 , seen=0.6490 , h=0.1365\n",
      "____________________________________________________________________________________________________\n",
      "episode: 400 loss tensor(3.0442, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.2861359158292243\n",
      "gzsl: unseen=0.1104 , seen=0.6458 , h=0.1885\n",
      "____________________________________________________________________________________________________\n",
      "episode: 600 loss tensor(3.0344, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.2828303241835805\n",
      "gzsl: unseen=0.0985 , seen=0.6564 , h=0.1712\n",
      "____________________________________________________________________________________________________\n",
      "episode: 800 loss tensor(3.0220, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.24916334326877634\n",
      "gzsl: unseen=0.1025 , seen=0.6183 , h=0.1758\n",
      "____________________________________________________________________________________________________\n",
      "episode: 1000 loss tensor(3.0150, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.25789407737131737\n",
      "gzsl: unseen=0.1290 , seen=0.5662 , h=0.2101\n",
      "____________________________________________________________________________________________________\n",
      "episode: 1200 loss tensor(3.0050, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.2758835466848511\n",
      "gzsl: unseen=0.1553 , seen=0.5658 , h=0.2436\n",
      "____________________________________________________________________________________________________\n",
      "episode: 1400 loss tensor(2.9783, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.31050602777004904\n",
      "gzsl: unseen=0.2066 , seen=0.5778 , h=0.3044\n",
      "____________________________________________________________________________________________________\n",
      "episode: 1600 loss tensor(2.8975, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3397243045383964\n",
      "gzsl: unseen=0.2050 , seen=0.5795 , h=0.3029\n",
      "____________________________________________________________________________________________________\n",
      "episode: 1800 loss tensor(2.7416, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3536631792844345\n",
      "gzsl: unseen=0.2333 , seen=0.5702 , h=0.3311\n",
      "____________________________________________________________________________________________________\n",
      "episode: 2000 loss tensor(2.7725, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3531512889275779\n",
      "gzsl: unseen=0.2519 , seen=0.5502 , h=0.3456\n",
      "____________________________________________________________________________________________________\n",
      "episode: 2200 loss tensor(2.6602, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3284002244314845\n",
      "gzsl: unseen=0.2517 , seen=0.5297 , h=0.3413\n",
      "____________________________________________________________________________________________________\n",
      "episode: 2400 loss tensor(2.5521, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.31711345146881204\n",
      "gzsl: unseen=0.2604 , seen=0.5195 , h=0.3469\n",
      "____________________________________________________________________________________________________\n",
      "episode: 2600 loss tensor(2.5128, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3186556152442058\n",
      "gzsl: unseen=0.2662 , seen=0.5155 , h=0.3511\n",
      "____________________________________________________________________________________________________\n",
      "episode: 2800 loss tensor(2.1224, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.32003014727005313\n",
      "gzsl: unseen=0.2607 , seen=0.5185 , h=0.3469\n",
      "____________________________________________________________________________________________________\n",
      "episode: 3000 loss tensor(2.3885, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.327166183907786\n",
      "gzsl: unseen=0.2702 , seen=0.5256 , h=0.3569\n",
      "____________________________________________________________________________________________________\n",
      "episode: 3200 loss tensor(2.1603, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.35828654750787553\n",
      "gzsl: unseen=0.2818 , seen=0.5212 , h=0.3658\n",
      "____________________________________________________________________________________________________\n",
      "episode: 3400 loss tensor(2.3470, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3413308103337229\n",
      "gzsl: unseen=0.2694 , seen=0.5356 , h=0.3585\n",
      "____________________________________________________________________________________________________\n",
      "episode: 3600 loss tensor(2.5680, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3304148632946782\n",
      "gzsl: unseen=0.2552 , seen=0.5536 , h=0.3494\n",
      "____________________________________________________________________________________________________\n",
      "episode: 3800 loss tensor(2.3584, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.35411853897726603\n",
      "gzsl: unseen=0.2698 , seen=0.5658 , h=0.3654\n",
      "____________________________________________________________________________________________________\n",
      "episode: 4000 loss tensor(2.3277, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33858659961462995\n",
      "gzsl: unseen=0.2509 , seen=0.5584 , h=0.3463\n",
      "____________________________________________________________________________________________________\n",
      "episode: 4200 loss tensor(2.3270, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3380613906847894\n",
      "gzsl: unseen=0.2488 , seen=0.5641 , h=0.3453\n",
      "____________________________________________________________________________________________________\n",
      "episode: 4400 loss tensor(2.4430, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.35079827129254726\n",
      "gzsl: unseen=0.2630 , seen=0.5719 , h=0.3603\n",
      "____________________________________________________________________________________________________\n",
      "episode: 4600 loss tensor(2.0858, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34565588438660105\n",
      "gzsl: unseen=0.2579 , seen=0.5823 , h=0.3575\n",
      "____________________________________________________________________________________________________\n",
      "episode: 4800 loss tensor(2.1998, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3329582067156044\n",
      "gzsl: unseen=0.2438 , seen=0.5755 , h=0.3425\n",
      "____________________________________________________________________________________________________\n",
      "episode: 5000 loss tensor(1.9534, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3332262468530773\n",
      "gzsl: unseen=0.2425 , seen=0.5739 , h=0.3409\n",
      "____________________________________________________________________________________________________\n",
      "episode: 5200 loss tensor(2.1724, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34006425701918047\n",
      "gzsl: unseen=0.2519 , seen=0.5736 , h=0.3501\n",
      "____________________________________________________________________________________________________\n",
      "episode: 5400 loss tensor(1.9049, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3466809777160293\n",
      "gzsl: unseen=0.2518 , seen=0.5855 , h=0.3521\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "episode: 5600 loss tensor(1.7968, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33351726739328935\n",
      "gzsl: unseen=0.2385 , seen=0.5852 , h=0.3389\n",
      "____________________________________________________________________________________________________\n",
      "episode: 5800 loss tensor(2.3311, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.346809686260827\n",
      "gzsl: unseen=0.2470 , seen=0.5822 , h=0.3468\n",
      "____________________________________________________________________________________________________\n",
      "episode: 6000 loss tensor(2.2075, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33193009347115626\n",
      "gzsl: unseen=0.2385 , seen=0.5893 , h=0.3396\n",
      "____________________________________________________________________________________________________\n",
      "episode: 6200 loss tensor(2.9729, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3382036205629792\n",
      "gzsl: unseen=0.2378 , seen=0.6052 , h=0.3414\n",
      "____________________________________________________________________________________________________\n",
      "episode: 6400 loss tensor(2.2362, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3387107144112733\n",
      "gzsl: unseen=0.2425 , seen=0.5999 , h=0.3454\n",
      "____________________________________________________________________________________________________\n",
      "episode: 6600 loss tensor(1.8126, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33461339480617175\n",
      "gzsl: unseen=0.2284 , seen=0.6111 , h=0.3325\n",
      "____________________________________________________________________________________________________\n",
      "episode: 6800 loss tensor(2.3860, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33562041102901047\n",
      "gzsl: unseen=0.2325 , seen=0.6160 , h=0.3375\n",
      "____________________________________________________________________________________________________\n",
      "episode: 7000 loss tensor(2.7084, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3410275019608527\n",
      "gzsl: unseen=0.2361 , seen=0.6158 , h=0.3413\n",
      "____________________________________________________________________________________________________\n",
      "episode: 7200 loss tensor(2.1525, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3409132008859213\n",
      "gzsl: unseen=0.2347 , seen=0.6241 , h=0.3411\n",
      "____________________________________________________________________________________________________\n",
      "episode: 7400 loss tensor(2.6895, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3480574639529694\n",
      "gzsl: unseen=0.2398 , seen=0.6197 , h=0.3458\n",
      "____________________________________________________________________________________________________\n",
      "episode: 7600 loss tensor(2.3738, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3268300646340995\n",
      "gzsl: unseen=0.2167 , seen=0.6228 , h=0.3215\n",
      "____________________________________________________________________________________________________\n",
      "episode: 7800 loss tensor(2.0404, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.32303317476629784\n",
      "gzsl: unseen=0.2162 , seen=0.6121 , h=0.3196\n",
      "____________________________________________________________________________________________________\n",
      "episode: 8000 loss tensor(2.3872, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33226570166955416\n",
      "gzsl: unseen=0.2176 , seen=0.6380 , h=0.3245\n",
      "____________________________________________________________________________________________________\n",
      "episode: 8200 loss tensor(1.8860, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33073790595693664\n",
      "gzsl: unseen=0.2148 , seen=0.6194 , h=0.3190\n",
      "____________________________________________________________________________________________________\n",
      "episode: 8400 loss tensor(2.5553, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3368783599736034\n",
      "gzsl: unseen=0.2111 , seen=0.6511 , h=0.3188\n",
      "____________________________________________________________________________________________________\n",
      "episode: 8600 loss tensor(2.1352, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3336580731734849\n",
      "gzsl: unseen=0.2166 , seen=0.6419 , h=0.3239\n",
      "____________________________________________________________________________________________________\n",
      "episode: 8800 loss tensor(1.7037, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33451753215630425\n",
      "gzsl: unseen=0.2041 , seen=0.6558 , h=0.3114\n",
      "____________________________________________________________________________________________________\n",
      "episode: 9000 loss tensor(2.3145, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33743725046241785\n",
      "gzsl: unseen=0.2141 , seen=0.6575 , h=0.3230\n",
      "____________________________________________________________________________________________________\n",
      "episode: 9200 loss tensor(1.9304, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3449271414193533\n",
      "gzsl: unseen=0.2206 , seen=0.6633 , h=0.3311\n",
      "____________________________________________________________________________________________________\n",
      "episode: 9400 loss tensor(2.1864, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33979947585337916\n",
      "gzsl: unseen=0.2139 , seen=0.6686 , h=0.3241\n",
      "____________________________________________________________________________________________________\n",
      "episode: 9600 loss tensor(2.2559, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3448551756654921\n",
      "gzsl: unseen=0.2187 , seen=0.6481 , h=0.3270\n",
      "____________________________________________________________________________________________________\n",
      "episode: 9800 loss tensor(1.7257, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3471056972314947\n",
      "gzsl: unseen=0.2232 , seen=0.6672 , h=0.3345\n",
      "____________________________________________________________________________________________________\n",
      "episode: 10000 loss tensor(2.5458, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34978010732497444\n",
      "gzsl: unseen=0.2225 , seen=0.6563 , h=0.3323\n",
      "____________________________________________________________________________________________________\n",
      "episode: 10200 loss tensor(2.1114, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34757264381583536\n",
      "gzsl: unseen=0.2272 , seen=0.6682 , h=0.3391\n",
      "____________________________________________________________________________________________________\n",
      "episode: 10400 loss tensor(1.8045, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.35107890599598385\n",
      "gzsl: unseen=0.2201 , seen=0.6750 , h=0.3319\n",
      "____________________________________________________________________________________________________\n",
      "episode: 10600 loss tensor(2.1004, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34686426282175303\n",
      "gzsl: unseen=0.2180 , seen=0.6631 , h=0.3281\n",
      "____________________________________________________________________________________________________\n",
      "episode: 10800 loss tensor(2.4130, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.36075436402477995\n",
      "gzsl: unseen=0.2250 , seen=0.6627 , h=0.3360\n",
      "____________________________________________________________________________________________________\n",
      "episode: 11000 loss tensor(1.9104, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3522920266169598\n",
      "gzsl: unseen=0.2266 , seen=0.6725 , h=0.3390\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "episode: 11200 loss tensor(1.6575, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34605729687466397\n",
      "gzsl: unseen=0.2105 , seen=0.6711 , h=0.3205\n",
      "____________________________________________________________________________________________________\n",
      "episode: 11400 loss tensor(2.2451, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34901380359999806\n",
      "gzsl: unseen=0.2175 , seen=0.6787 , h=0.3294\n",
      "____________________________________________________________________________________________________\n",
      "episode: 11600 loss tensor(1.9879, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34697012460045507\n",
      "gzsl: unseen=0.2031 , seen=0.7000 , h=0.3149\n",
      "____________________________________________________________________________________________________\n",
      "episode: 11800 loss tensor(2.6079, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34664536754381414\n",
      "gzsl: unseen=0.2011 , seen=0.6964 , h=0.3121\n",
      "____________________________________________________________________________________________________\n",
      "episode: 12000 loss tensor(1.9716, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3516209083960604\n",
      "gzsl: unseen=0.2234 , seen=0.6888 , h=0.3374\n",
      "____________________________________________________________________________________________________\n",
      "episode: 12200 loss tensor(3.0779, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3500512951572375\n",
      "gzsl: unseen=0.2120 , seen=0.7018 , h=0.3256\n",
      "____________________________________________________________________________________________________\n",
      "episode: 12400 loss tensor(2.2869, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.35393544581719955\n",
      "gzsl: unseen=0.2189 , seen=0.6918 , h=0.3326\n",
      "____________________________________________________________________________________________________\n",
      "episode: 12600 loss tensor(3.1330, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.35195163255005674\n",
      "gzsl: unseen=0.2223 , seen=0.6979 , h=0.3372\n",
      "____________________________________________________________________________________________________\n",
      "episode: 12800 loss tensor(2.6723, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3509396337173804\n",
      "gzsl: unseen=0.2175 , seen=0.6944 , h=0.3312\n",
      "____________________________________________________________________________________________________\n",
      "episode: 13000 loss tensor(2.9544, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3520769269944053\n",
      "gzsl: unseen=0.2170 , seen=0.7074 , h=0.3321\n",
      "____________________________________________________________________________________________________\n",
      "episode: 13200 loss tensor(2.6560, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.35483848462210527\n",
      "gzsl: unseen=0.2278 , seen=0.7097 , h=0.3449\n",
      "____________________________________________________________________________________________________\n",
      "episode: 13400 loss tensor(2.2301, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3508258132076389\n",
      "gzsl: unseen=0.2164 , seen=0.7049 , h=0.3311\n",
      "____________________________________________________________________________________________________\n",
      "episode: 13600 loss tensor(2.3330, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3512574787408384\n",
      "gzsl: unseen=0.2181 , seen=0.7260 , h=0.3354\n",
      "____________________________________________________________________________________________________\n",
      "episode: 13800 loss tensor(2.8269, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3462569891840828\n",
      "gzsl: unseen=0.2157 , seen=0.7240 , h=0.3324\n",
      "____________________________________________________________________________________________________\n",
      "episode: 14000 loss tensor(2.0858, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3509894756108356\n",
      "gzsl: unseen=0.2321 , seen=0.7365 , h=0.3530\n",
      "____________________________________________________________________________________________________\n",
      "episode: 14200 loss tensor(2.1325, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3446434033025998\n",
      "gzsl: unseen=0.2163 , seen=0.7491 , h=0.3357\n",
      "____________________________________________________________________________________________________\n",
      "episode: 14400 loss tensor(1.4135, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34790843565913826\n",
      "gzsl: unseen=0.2164 , seen=0.7569 , h=0.3366\n",
      "____________________________________________________________________________________________________\n",
      "episode: 14600 loss tensor(1.4845, device='cuda:0')\n",
      "loss_zero_number=  1\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34815209833090943\n",
      "gzsl: unseen=0.2081 , seen=0.7597 , h=0.3267\n",
      "____________________________________________________________________________________________________\n",
      "episode: 14800 loss tensor(2.2983, device='cuda:0')\n",
      "loss_zero_number=  1\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3448464844395151\n",
      "gzsl: unseen=0.2187 , seen=0.7644 , h=0.3400\n",
      "____________________________________________________________________________________________________\n",
      "episode: 15000 loss tensor(0.9529, device='cuda:0')\n",
      "loss_zero_number=  1\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3419209020784757\n",
      "gzsl: unseen=0.2202 , seen=0.7349 , h=0.3388\n",
      "____________________________________________________________________________________________________\n",
      "episode: 15200 loss tensor(1.5945, device='cuda:0')\n",
      "loss_zero_number=  2\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3396425142721223\n",
      "gzsl: unseen=0.2069 , seen=0.7556 , h=0.3248\n",
      "____________________________________________________________________________________________________\n",
      "episode: 15400 loss tensor(0.4240, device='cuda:0')\n",
      "loss_zero_number=  4\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33839464761222177\n",
      "gzsl: unseen=0.2048 , seen=0.7523 , h=0.3219\n",
      "____________________________________________________________________________________________________\n",
      "episode: 15600 loss tensor(0.5495, device='cuda:0')\n",
      "loss_zero_number=  3\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3381362970958563\n",
      "gzsl: unseen=0.2093 , seen=0.7487 , h=0.3272\n",
      "____________________________________________________________________________________________________\n",
      "episode: 15800 loss tensor(0.5260, device='cuda:0')\n",
      "loss_zero_number=  5\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.34227731136300527\n",
      "gzsl: unseen=0.2187 , seen=0.7494 , h=0.3386\n",
      "____________________________________________________________________________________________________\n",
      "episode: 16000 loss tensor(1.4271, device='cuda:0')\n",
      "loss_zero_number=  4\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.339644227029877\n",
      "gzsl: unseen=0.2110 , seen=0.7561 , h=0.3299\n",
      "____________________________________________________________________________________________________\n",
      "episode: 16200 loss tensor(0.7235, device='cuda:0')\n",
      "loss_zero_number=  5\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3345028776086627\n",
      "gzsl: unseen=0.2079 , seen=0.7505 , h=0.3256\n",
      "____________________________________________________________________________________________________\n",
      "episode: 16400 loss tensor(2.2808, device='cuda:0')\n",
      "loss_zero_number=  3\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3469038906234822\n",
      "gzsl: unseen=0.2116 , seen=0.7630 , h=0.3313\n",
      "____________________________________________________________________________________________________\n",
      "episode: 16600 loss tensor(0.9454, device='cuda:0')\n",
      "loss_zero_number=  10\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3388904695335691\n",
      "gzsl: unseen=0.2078 , seen=0.7533 , h=0.3258\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "episode: 16800 loss tensor(0.3443, device='cuda:0')\n",
      "loss_zero_number=  13\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33328522986416637\n",
      "gzsl: unseen=0.1981 , seen=0.7654 , h=0.3148\n",
      "____________________________________________________________________________________________________\n",
      "episode: 17000 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  39\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.32471821992456146\n",
      "gzsl: unseen=0.1957 , seen=0.7659 , h=0.3117\n",
      "____________________________________________________________________________________________________\n",
      "episode: 17200 loss tensor(1.1432, device='cuda:0')\n",
      "loss_zero_number=  45\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33701693273412386\n",
      "gzsl: unseen=0.2005 , seen=0.7566 , h=0.3170\n",
      "____________________________________________________________________________________________________\n",
      "episode: 17400 loss tensor(0.1107, device='cuda:0')\n",
      "loss_zero_number=  42\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33452998199934897\n",
      "gzsl: unseen=0.1959 , seen=0.7739 , h=0.3126\n",
      "____________________________________________________________________________________________________\n",
      "episode: 17600 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  53\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3250876194948113\n",
      "gzsl: unseen=0.2004 , seen=0.7730 , h=0.3183\n",
      "____________________________________________________________________________________________________\n",
      "episode: 17800 loss tensor(0.2298, device='cuda:0')\n",
      "loss_zero_number=  78\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3303792951528282\n",
      "gzsl: unseen=0.1990 , seen=0.7661 , h=0.3159\n",
      "____________________________________________________________________________________________________\n",
      "episode: 18000 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  77\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33861402674413266\n",
      "gzsl: unseen=0.1987 , seen=0.7682 , h=0.3158\n",
      "____________________________________________________________________________________________________\n",
      "episode: 18200 loss tensor(0.3015, device='cuda:0')\n",
      "loss_zero_number=  76\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33241906902569746\n",
      "gzsl: unseen=0.1903 , seen=0.7752 , h=0.3056\n",
      "____________________________________________________________________________________________________\n",
      "episode: 18400 loss tensor(0.2809, device='cuda:0')\n",
      "loss_zero_number=  112\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3394567229626549\n",
      "gzsl: unseen=0.2049 , seen=0.7649 , h=0.3232\n",
      "____________________________________________________________________________________________________\n",
      "episode: 18600 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  107\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33206749898710847\n",
      "gzsl: unseen=0.1935 , seen=0.7610 , h=0.3086\n",
      "____________________________________________________________________________________________________\n",
      "episode: 18800 loss tensor(0.1592, device='cuda:0')\n",
      "loss_zero_number=  113\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33066236922738473\n",
      "gzsl: unseen=0.1878 , seen=0.7697 , h=0.3020\n",
      "____________________________________________________________________________________________________\n",
      "episode: 19000 loss tensor(0.1583, device='cuda:0')\n",
      "loss_zero_number=  122\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33040685675209175\n",
      "gzsl: unseen=0.1823 , seen=0.7761 , h=0.2952\n",
      "____________________________________________________________________________________________________\n",
      "episode: 19200 loss tensor(0.1598, device='cuda:0')\n",
      "loss_zero_number=  113\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3307814953770858\n",
      "gzsl: unseen=0.1794 , seen=0.7769 , h=0.2915\n",
      "____________________________________________________________________________________________________\n",
      "episode: 19400 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  114\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.329932782879067\n",
      "gzsl: unseen=0.1861 , seen=0.7659 , h=0.2994\n",
      "____________________________________________________________________________________________________\n",
      "episode: 19600 loss tensor(0.3330, device='cuda:0')\n",
      "loss_zero_number=  135\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3300752601358165\n",
      "gzsl: unseen=0.1910 , seen=0.7807 , h=0.3069\n",
      "____________________________________________________________________________________________________\n",
      "episode: 19800 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  117\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33170272039156407\n",
      "gzsl: unseen=0.1901 , seen=0.7806 , h=0.3057\n",
      "____________________________________________________________________________________________________\n",
      "episode: 20000 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  123\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3340219794639976\n",
      "gzsl: unseen=0.1885 , seen=0.7890 , h=0.3043\n",
      "____________________________________________________________________________________________________\n",
      "episode: 20200 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  152\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3297794692408945\n",
      "gzsl: unseen=0.1819 , seen=0.7912 , h=0.2958\n",
      "____________________________________________________________________________________________________\n",
      "episode: 20400 loss tensor(0.1242, device='cuda:0')\n",
      "loss_zero_number=  149\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33681025218685595\n",
      "gzsl: unseen=0.2000 , seen=0.7854 , h=0.3188\n",
      "____________________________________________________________________________________________________\n",
      "episode: 20600 loss tensor(0.2223, device='cuda:0')\n",
      "loss_zero_number=  148\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3406077780922771\n",
      "gzsl: unseen=0.1918 , seen=0.7838 , h=0.3081\n",
      "____________________________________________________________________________________________________\n",
      "episode: 20800 loss tensor(0.1538, device='cuda:0')\n",
      "loss_zero_number=  152\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3373419142014454\n",
      "gzsl: unseen=0.1839 , seen=0.7873 , h=0.2982\n",
      "____________________________________________________________________________________________________\n",
      "episode: 21000 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  151\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3308014460652792\n",
      "gzsl: unseen=0.1861 , seen=0.7748 , h=0.3002\n",
      "____________________________________________________________________________________________________\n",
      "episode: 21200 loss tensor(1.0264, device='cuda:0')\n",
      "loss_zero_number=  162\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3283896805343007\n",
      "gzsl: unseen=0.1788 , seen=0.7757 , h=0.2907\n",
      "____________________________________________________________________________________________________\n",
      "episode: 21400 loss tensor(0.3910, device='cuda:0')\n",
      "loss_zero_number=  150\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3176273562852492\n",
      "gzsl: unseen=0.1707 , seen=0.7797 , h=0.2800\n",
      "____________________________________________________________________________________________________\n",
      "episode: 21600 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  153\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33524424141660925\n",
      "gzsl: unseen=0.1855 , seen=0.7726 , h=0.2992\n",
      "____________________________________________________________________________________________________\n",
      "episode: 21800 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  169\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33627984676627315\n",
      "gzsl: unseen=0.1832 , seen=0.7947 , h=0.2977\n",
      "____________________________________________________________________________________________________\n",
      "episode: 22000 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  153\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.33556466331244245\n",
      "gzsl: unseen=0.1777 , seen=0.7850 , h=0.2898\n",
      "____________________________________________________________________________________________________\n",
      "episode: 22200 loss tensor(0., device='cuda:0')\n",
      "loss_zero_number=  158\n",
      "Testing...\n",
      "class num: 12\n",
      "class num: 32\n",
      "class num: 32\n",
      "zsl: 0.3299963236475571\n",
      "gzsl: unseen=0.1771 , seen=0.7853 , h=0.2890\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-8-d055b599044c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     31\u001b[0m     \u001b[0mcriterion\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mHardTripletLoss_D\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmargin\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMargin\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcuda\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mGPU\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     32\u001b[0m     triplet_loss= criterion(metric_network(attribute_network(batch_attributes_ext)), \n\u001b[0;32m---> 33\u001b[0;31m                             metric_network(batch_features_ext), re_batch_labels)\n\u001b[0m\u001b[1;32m     34\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mtriplet_loss\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     35\u001b[0m         \u001b[0mloss_zero_num\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mloss_zero_num\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/workspace/wanghai/anaconda3/envs/pytorch/lib/python3.5/site-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m    489\u001b[0m             \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_slow_forward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    490\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 491\u001b[0;31m             \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    492\u001b[0m         \u001b[0;32mfor\u001b[0m \u001b[0mhook\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_forward_hooks\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    493\u001b[0m             \u001b[0mhook_result\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mhook\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/workspace/wanghai/My_Zero_shot/baseline1/My_Loss.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, attributes, embeddings, labels)\u001b[0m\n\u001b[1;32m    155\u001b[0m         \u001b[0;31m#print(relations.size())\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    156\u001b[0m         \u001b[0;31m# Get the hardest positive pairs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 157\u001b[0;31m         \u001b[0mmask_pos\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0m_get_anchor_positive_triplet_mask\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrelations\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabels\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    158\u001b[0m         \u001b[0;31m#print(mask_pos)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    159\u001b[0m         \u001b[0mvalid_positive_dist\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrelations\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mmask_pos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/workspace/wanghai/My_Zero_shot/baseline1/My_Loss.py\u001b[0m in \u001b[0;36m_get_anchor_positive_triplet_mask\u001b[0;34m(relations, labels)\u001b[0m\n\u001b[1;32m    207\u001b[0m     \u001b[0mmask_pos\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros_like\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrelations\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbyte\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    208\u001b[0m     \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrelations\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 209\u001b[0;31m         \u001b[0mmask_pos\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mlabels\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    210\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    211\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0mmask_pos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "print(\"training...\")\n",
    "last_accuracy = 0.0\n",
    "loss_zero_num = 0\n",
    "#writer = SummaryWriter()\n",
    "for episode in range(EPISODE):\n",
    "    #attribute_network.train()\n",
    "    attribute_network_scheduler.step(episode)\n",
    "    metric_network_scheduler.step(episode)\n",
    "\n",
    "    train_loader = DataLoader(train_data, batch_size=BATCH_SIZE, shuffle=True)\n",
    "\n",
    "    batch_labels, batch_features = train_loader.__iter__().next()\n",
    "    batch_id = np.unique(batch_labels)\n",
    "\n",
    "    batch_attributes = torch.Tensor([all_attributes[i] for i in batch_id]).squeeze(1)\n",
    "    batch_features_ext = torch.from_numpy(batch_features.numpy().repeat(batch_id.size, 0))\n",
    "    batch_attributes_ext = batch_attributes.repeat(BATCH_SIZE, 1)\n",
    "\n",
    "    batch_features_ext = Variable(batch_features_ext).cuda(GPU).float()  # 32*2048\n",
    "    batch_attributes_ext = Variable(batch_attributes_ext).cuda(GPU)\n",
    "    \n",
    "\n",
    "    re_batch_labels = []\n",
    "    for label in batch_labels.numpy():\n",
    "        index = np.argwhere(batch_id == label)\n",
    "        re_batch_labels.append(index[0][0])\n",
    "    re_batch_labels = torch.cuda.LongTensor(re_batch_labels)\n",
    "    re_batch_labels = Variable(re_batch_labels).cuda(GPU)\n",
    "    \n",
    "\n",
    "    criterion = HardTripletLoss_D(margin = Margin).cuda(GPU)\n",
    "    triplet_loss= criterion(metric_network(attribute_network(batch_attributes_ext)), \n",
    "                            metric_network(batch_features_ext), re_batch_labels)\n",
    "    if triplet_loss == 0:\n",
    "        loss_zero_num = loss_zero_num + 1\n",
    "    metric_network.zero_grad()\n",
    "    attribute_network.zero_grad()\n",
    "    \n",
    "    triplet_loss.backward()\n",
    "    \n",
    "    attribute_network_optim.step()\n",
    "    metric_network_optim.step()\n",
    "    \n",
    "    if (episode+1)%200 == 0 or episode==0:\n",
    "        print(\"episode:\", episode+1, \"loss\", triplet_loss)\n",
    "        print('loss_zero_number= ',loss_zero_num)\n",
    "        #writer.add_scalar('data/loss_zero_number', loss_zero_num, episode)\n",
    "        loss_zero_num = 0\n",
    "        #writer.add_scalar('data/loss', triplet_loss, episode)\n",
    "    if (episode+1)%200 == 0 or episode==0:\n",
    "        print(\"Testing...\")\n",
    "        #attribute_network.eval()\n",
    "        zsl_accuracy = compute_accuracy_per_class(test_features, test_label, test_id, test_attributes)\n",
    "        gzsl_unseen_accuracy = compute_accuracy_per_class(test_features, test_label, np.arange(32), attributes)\n",
    "        gzsl_seen_accuracy = compute_accuracy_per_class(test_seen_features, test_seen_label, np.arange(32), attributes)\n",
    "        H = 2 * gzsl_seen_accuracy * gzsl_unseen_accuracy / (gzsl_unseen_accuracy + gzsl_seen_accuracy)\n",
    "        #H2 = 2 * gzsl_seen_accuracy2 * gzsl_unseen_accuracy2 / (gzsl_unseen_accuracy2 + gzsl_seen_accuracy2)\n",
    "        print('zsl:', zsl_accuracy)\n",
    "        #print('zsl:', zsl_accuracy2)\n",
    "        print('gzsl: unseen=%.4f , seen=%.4f , h=%.4f' % (gzsl_unseen_accuracy , gzsl_seen_accuracy, H))\n",
    "        #print('gzsl: unseen=%.4f , seen=%.4f , h=%.4f' % (gzsl_unseen_accuracy2 , gzsl_seen_accuracy2, H2))\n",
    "        print('_'*100)\n",
    "        #writer.add_scalar('data/zsl_accuracy', zsl_accuracy, episode)\n",
    "        #writer.add_scalar('data/gzsl_unseen_accuracy', gzsl_unseen_accuracy, episode)\n",
    "        #writer.add_scalar('data/gzsl_seen_accuracy', gzsl_seen_accuracy, episode)\n",
    "        #writer.add_scalar('data/H', H, episode)\n",
    "#writer.export_scalars_to_json(\"./test.json\")\n",
    "#writer.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "pytorch"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
